﻿namespace Pub.Class
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Threading;

    public static class IntExtensions
    {
        public static DateTime DaysAgo(this int days)
        {
            return DateTime.Now.AddDays((double) -days);
        }

        public static bool False(this int iBool)
        {
            return !iBool.ToBool();
        }

        public static string FormatBytes(this int bytes)
        {
            return ((long) bytes).FormatBytes();
        }

        public static string FormatKB(this int bytes)
        {
            return ((long) bytes).FormatKB();
        }

        public static DateTime HoursAgo(this int hours)
        {
            return DateTime.Now.AddHours((double) -hours);
        }

        public static int IfEqual(this int obj, int value, int defaultValue)
        {
            if (obj != value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static int IfLessThan(this int obj, int value, int defaultValue)
        {
            if (obj >= value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static int IfLessThanOrEqual(this int obj, int value, int defaultValue)
        {
            if (obj > value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static int IfMoreThan(this int obj, int value, int defaultValue)
        {
            if (obj <= value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static int IfMoreThanOrEqual(this int obj, int value, int defaultValue)
        {
            if (obj < value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static int IfNotEqual(this int obj, int value, int defaultValue)
        {
            if (obj == value)
            {
                return obj;
            }
            return defaultValue;
        }

        public static bool IsBetween(this int i, int lowerBound, int upperBound)
        {
            return i.IsBetween(lowerBound, upperBound, false);
        }

        public static bool IsBetween(this int i, int lowerBound, int upperBound, bool includeBounds)
        {
            if (includeBounds)
            {
                return ((i >= lowerBound) && (i <= upperBound));
            }
            return ((i > lowerBound) && (i < upperBound));
        }

        public static bool IsEven(this int iInt)
        {
            return iInt.IsMod(2);
        }

        public static bool IsMod(this int iInt, int val)
        {
            return ((iInt % val) == 0);
        }

        public static bool IsOdd(this int value)
        {
            return ((value & 1) == 1);
        }

        public static bool IsPrime<T>(this int ToBeChecked)
        {
            BitArray array = new BitArray(ToBeChecked + 1, true);
            for (int i = 2; i < (ToBeChecked + 1); i++)
            {
                if (array[i])
                {
                    for (int j = i * 2; j < (ToBeChecked + 1); j += i)
                    {
                        array[j] = false;
                    }
                    if (array[i] && (ToBeChecked == i))
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        public static string Jammer(this int len)
        {
            string str = string.Empty;
            for (int i = 0; i < len; i++)
            {
                str = str + ((char) Rand.RndInt(0, 0x21)).ToString() + ((char) Rand.RndInt(0x3f, 0x7e)).ToString();
            }
            return str;
        }

        public static DateTime MinutesAgo(this int minutes)
        {
            return DateTime.Now.AddMinutes((double) -minutes);
        }

        public static DateTime MonthsAgo(this int months)
        {
            return DateTime.Now.AddMonths(-months);
        }

        public static decimal PercentageOf(this int number, decimal percent)
        {
            return ((number * percent) / 100M);
        }

        public static decimal PercentageOf(this int number, double percent)
        {
            return (decimal) ((number * percent) / 100.0);
        }

        public static decimal PercentageOf(this int number, int percent)
        {
            return ((number * percent) / 100);
        }

        public static decimal PercentageOf(this int number, long percent)
        {
            return ((number * percent) / 100L);
        }

        public static decimal PercentageOf(this int number, float percent)
        {
            return (decimal) ((number * percent) / 100f);
        }

        public static decimal PercentOf(this int position, decimal total)
        {
            decimal num = 0M;
            if ((position > 0) && (total > 0M))
            {
                num = (position / total) * 100M;
            }
            return num;
        }

        public static decimal PercentOf(this int position, double total)
        {
            decimal num = 0M;
            if ((position > 0) && (total > 0.0))
            {
                num = (position / ((decimal) total)) * 100M;
            }
            return num;
        }

        public static decimal PercentOf(this int position, int total)
        {
            decimal num = 0M;
            if ((position > 0) && (total > 0))
            {
                num = (position / total) * 100M;
            }
            return num;
        }

        public static decimal PercentOf(this int position, long total)
        {
            decimal num = 0M;
            if ((position > 0) && (total > 0L))
            {
                num = (position / total) * 100M;
            }
            return num;
        }

        public static decimal PercentOf(this int position, float total)
        {
            decimal num = 0M;
            if ((position > 0) && (total > 0f))
            {
                num = (position / ((decimal) total)) * 100M;
            }
            return num;
        }

        public static decimal PercentOf(this int? position, int total)
        {
            if (position.IsNull())
            {
                return 0M;
            }
            decimal num = 0M;
            if ((position > 0) && (total > 0))
            {
                num = (position.Value / total) * 100M;
            }
            return num;
        }

        public static IEnumerable<int> Range(this int start, int end)
        {
            int iteratorVariable0 = start;
            while (true)
            {
                if (iteratorVariable0 > end)
                {
                    yield break;
                }
                yield return iteratorVariable0;
                iteratorVariable0++;
            }
        }

        public static DateTime SecondsAgo(this int seconds)
        {
            return DateTime.Now.AddSeconds((double) -seconds);
        }

        public static int Sleep(this int ms)
        {
            Thread.Sleep(ms);
            return ms;
        }

        public static bool ToBool(this int val)
        {
            if (val <= 0)
            {
                return false;
            }
            return true;
        }

        public static string ToCurrency(this int value)
        {
            return value.ToString("N");
        }

        public static T ToEnum<T>(this int number)
        {
            return (T) Enum.ToObject(typeof(T), number);
        }

        public static string ToOctal(this int n)
        {
            return string.Format("{0:X8}", n);
        }

        public static string ToOctal(this long n)
        {
            return string.Format("{0:X8}", n);
        }

        public static string ToRMB(this int value)
        {
            return value.ToRMB();
        }

        public static string ToTime(this int seconds)
        {
            return ((long) seconds).ToTime();
        }

        public static TimeSpan ToTimeSpan(this int integer)
        {
            int hours = integer / 100;
            return new TimeSpan(hours, integer - (hours * 100), 0);
        }

        public static bool True(this int iBool)
        {
            return iBool.ToBool();
        }

        public static DateTime YearsAgo(this int years)
        {
            return DateTime.Now.AddYears(-years);
        }

    }
}

